home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 7
/
Apprentice-Release7.iso
/
Demos
/
A.D. Software
/
OOFILE 1.3b4d6.sit
/
OOFILE 1.3b4d6
/
OOFGraph 1.0b2 Demo
/
Application Source
/
GrTstApp.cp
next >
Wrap
Text File
|
1997-04-08
|
12KB
|
464 lines
// ===========================================================================
// GrTstApp.cp Derived heavily from the Dashboard Starter
// ===========================================================================
//
#include "GrTstApp.h"
#include <LApplication.h>
#include <LGrowZone.h>
#include <LWindow.h>
#include <UDrawingState.h>
#include <UMemoryMgr.h>
#include <URegistrar.h>
#include "math.h"
#include "oofGrPP.h"
#include "oofGrphs.h" // because we create bar & col graphs here
#ifdef OOF_SmartHeap
#include "smrtheap.hpp"
#endif
// ===========================================================================
// * Main Program
// ===========================================================================
void main()
{
// Set Debugging options
SetDebugThrow_(debugAction_Alert);
SetDebugSignal_(debugAction_Alert);
InitializeHeap(3); // Initialize Memory Manager
// Parameter is number of Master Pointer
// blocks to allocate
// Initialize standard Toolbox managers
UQDGlobals::InitializeToolbox(&qd);
new LGrowZone(20000); // Install a GrowZone function to catch
// low memory situations.
// Parameter is size of reserve memory
// block to allocated. The first time
// the GrowZone function is called,
// there will be at least this much
// memory left (so you'll have enough
// memory to alert the user or finish
// what you are doing).
GraphTestApp theApp; // Create instance of your Application
theApp.Run(); // class and run it
}
// ===========================================================================
// * GraphTestApp Class
// ===========================================================================
// ---------------------------------------------------------------------------
// * GraphTestApp
// ---------------------------------------------------------------------------
// Constructor
void
GraphTestApp::Initialize()
{
// DEFINE THE DATABASES
dbConnect_ram theDB;
dbStudent Students;
dbOverlay Overlay;
dbStudentOverlay StudentsOverlay;
dbTemperature Temperatures;
dbExports Exports;
dbMath Math;
// dbSales Sales;
theDB.newConnection("Databases");
Students.AddTestData();
Overlay.AddTestData();
StudentsOverlay.AddTestData();
Temperatures.AddTestData();
Exports.AddTestData();
Math.AddTestData();
// Sales.AddTestData();
Students.setSortOrder(dbSorter() << Students.Name << Students.Subject);
dbView Sview(Students, false);
Sview << Students.Name << Students.Subject << Students.Mark;
Overlay.setSortOrder(Overlay.Name);
dbView Oview(Overlay, false);
Oview << Overlay.LastYear;
// NOTE: StudentOverlay is NOT sorted due to the necessary nature of the ordering
// of the subject fields with regards to the overlay !
//
// NOTE ALSO: that even sorting by name is dangerous because the standard non-indexed
// sort affects (reverses) the order of the other fields - by consequence
// this graph is displayed with the students in a different order
dbView SviewOverlay(StudentsOverlay, false);
SviewOverlay << StudentsOverlay.Name << StudentsOverlay.Subject << StudentsOverlay.Mark;
dbView Tview(Temperatures);
Tview << Temperatures.Day << Temperatures.Time << Temperatures.Temp;
Exports.setSortOrder(dbSorter() << Exports.Year << Exports.Port);
dbView Eview(Exports, false);
Eview << Exports.Year << Exports.Port << Exports.Value << Exports.Outcome;
dbView Mview(Math);
Mview << Math.Name << Math.Xval << Math.Yval;
// dbView Sales_view(Sales);
// Sales_view << Sales.Year << Sales.State << Sales.Sales;
// OK - Let's get Powerplant to work
// Register the functions to create our custom Pane classes
oofGraphWindow::RegisterClass();
// Do the Stuff !
// oofGraphWindow::CreateColumnGraphWindow(this, &Sales_view, "Lots of\nSales");
// change some default settings
oofGraphDefaultSettings::settings()->hasYLabel(false);
oofGraphDefaultSettings::settings()->realTickLabelMask("%5.3f");
// create some graphs with default settings
oofGraphWindow::CreateStackedBarGraphWindow(this, &Tview, "Daily Temperatures");
oofGraphWindow::CreateStackedBarGraphWindowWithOverlay(this, &SviewOverlay, "Student Grade Average",
2 /* last 2 data series are overlaid */);
oofGraphWindow::CreateStackedBarGraphWindowWithOverlayView(this, &Sview, "Student Grade Average",&Oview);
oofGraphWindow::CreateOrdinalStackedBarGraphWindow(this, &Eview, "Port Profitability");
oofGraphWindow::CreateLineGraphWindow(this, &Sview, "Student Grade Average", 100);
oofGraphWindow::CreateXYGraphWindow(this, &Mview, "Some Transcendentals");
// create graphs with different settings
oofBarGraph* theBar = new oofBarGraph;
theBar->getLocalSettings()->hasValuesNextToBars(true);
oofGraphWindow::CreateWindow(this, theBar, &Tview, "Daily Temperatures");
oofColumnGraph* theCol = new oofColumnGraph;
theCol->getLocalSettings()->hasValuesOverColumns(true);
oofGraphWindow::CreateWindow(this, theCol, &Sview, "Student Grade Average", 100);
}
// ---------------------------------------------------------------------------
// * ~GraphTest
// ---------------------------------------------------------------------------
// Destructor
GraphTestApp::~GraphTestApp()
{
}
// ---------------------------------------------------------------------------
// * ObeyCommand
// ---------------------------------------------------------------------------
// Respond to commands
Boolean
GraphTestApp::ObeyCommand(
CommandT inCommand,
void *ioParam)
{
Boolean cmdHandled = true;
switch (inCommand) {
default:
cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
break;
}
return cmdHandled;
}
// ---------------------------------------------------------------------------
// * FindCommandStatus
// ---------------------------------------------------------------------------
// Pass back status of a (menu) command
void
GraphTestApp::FindCommandStatus(
CommandT inCommand,
Boolean &outEnabled,
Boolean &outUsesMark,
Char16 &outMark,
Str255 outName)
{
switch (inCommand) {
default:
LApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark,
outMark, outName);
break;
}
}
// ===========================================================================
// * Student test data
// ===========================================================================
void dbStudent::Add(const char *name, const char *subject, const long mark)
{
newRecord();
Name = name;
Subject = subject;
Mark = mark;
saveRecord();
}
void dbStudent::AddTestData()
{
Add("Alice Chan", "Maths", 62);
Add("Alice Chan", "Social Studies", 72);
Add("Alice Chan", "English", 65);
Add("Alice Chan", "Science", 82);
Add("Kathy Robins", "Maths", 82);
Add("Kathy Robins", "Social Studies", 54);
Add("Kathy Robins", "English", 44);
Add("Kathy Robins", "Science", 75);
Add("Brett Baker", "Maths", 65);
Add("Brett Baker", "Social Studies", 78);
Add("Brett Baker", "English", 64);
Add("Brett Baker", "Science", 72);
Add("Jack Smith", "Maths", 71);
Add("Jack Smith", "English", 56);
Add("Jack Smith", "Science", 81);
Add("Jack Smith", "Social Studies", 35);
}
// ===========================================================================
// * overlay item for student data
// ===========================================================================
void dbOverlay::Add(const char *name, const long lastyear)
{
newRecord();
Name = name;
LastYear = lastyear;
saveRecord();
}
void dbOverlay::AddTestData()
{
Add("Alice Chan", 290);
Add("Kathy Robins", 220);
Add("Brett Baker", 270);
Add("Jack Smith", 250);
}
// ===========================================================================
// * Student test data with overlay item
// ===========================================================================
void dbStudentOverlay::Add(const char *name, const char *subject, const long mark)
{
newRecord();
Name = name;
Subject = subject;
Mark = mark;
saveRecord();
}
void dbStudentOverlay::AddTestData()
{
Add("Alice Chan", "Maths", 62);
Add("Alice Chan", "Social Studies", 72);
Add("Alice Chan", "English", 65);
Add("Alice Chan", "Science", 82);
Add("Alice Chan", "Last Year", 290);
Add("Kathy Robins", "Maths", 82);
Add("Kathy Robins", "Social Studies", 54);
Add("Kathy Robins", "English", 44);
Add("Kathy Robins", "Science", 75);
Add("Kathy Robins", "Last Year", 220);
Add("Brett Baker", "Maths", 65);
Add("Brett Baker", "Social Studies", 78);
Add("Brett Baker", "English", 64);
Add("Brett Baker", "Science", 72);
Add("Brett Baker", "Last Year", 270);
Add("Jack Smith", "Maths", 71);
Add("Jack Smith", "Social Studies", 35);
Add("Jack Smith", "English", 56);
Add("Jack Smith", "Science", 81);
Add("Jack Smith", "Last Year", 250);
}
// ===========================================================================
// * Math Test Data
// ===========================================================================
void dbMath::Add(const char *name, const double x, const double y)
{
newRecord();
Name = name;
Xval = x;
Yval = y;
saveRecord();
}
void dbMath::AddTestData()
{
for(double theta=0;theta<6.3;theta=theta+0.157){
Add("Sine Wave (+1)",theta,(sin(theta)+1.0));
Add("Cosine Wave (+1)",theta,(cos(theta)+1.0));
}
}
// ===========================================================================
// * Temperature Test Data
// ===========================================================================
void dbTemperature::Add(const char *day, const char *time, const long temp)
{
newRecord();
Day = day;
Time = time;
Temp = temp;
saveRecord();
}
void dbTemperature::AddTestData()
{
Add("Sun", "Day", 22);
Add("Sun", "Night", 12);
Add("Mon", "Day", 24);
Add("Mon", "Night", 12);
Add("Tue", "Day", 24);
Add("Tue", "Night", 10);
Add("Wed", "Day", 27);
Add("Wed", "Night", 14);
Add("Thu", "Day", 25);
Add("Thu", "Night", 12);
Add("Fri", "Day", 22);
Add("Fri", "Night", 10);
Add("Sat", "Day", 19);
Add("Sat", "Night", 8);
}
// ===========================================================================
// * Exports Test Data
// ===========================================================================
void dbExports::Add(const char *year, const char *port, const double value, const char *outcome)
{
newRecord();
Year = year;
Port = port;
Value = value;
Outcome = outcome;
saveRecord();
}
void dbExports::AddTestData()
{
Add("1993", "Fremantle", 12.3, "Profit");
Add("1993", "Geraldton", 8.1, "Break Even");
Add("1993", "Bunbury", 5.3, "Loss");
Add("1994", "Fremantle", 16.1, "Break Even");
Add("1994", "Geraldton", 9.0, "Break Even");
Add("1994", "Bunbury", 10.9, "Profit");
Add("1995", "Fremantle", 16.4, "Loss");
Add("1995", "Geraldton", 10.3, "Break Even");
Add("1995", "Bunbury", 10.8, "Break Even");
}
/*
// ===========================================================================
// * Sales Test Data
// ===========================================================================
void dbSales::Add(const char *year, const char *state, const long sales)
{
newRecord();
Year = year;
State = state;
Sales = sales;
saveRecord();
}
void dbSales::AddTestData()
{
Add("1994", "WA", 200);
Add("1994", "SA", 145);
Add("1994", "QLD", 65);
Add("1994", "VIC", 120);
Add("1994", "NSW", 180);
Add("1994", "TAS", 55);
Add("1994", "NT", 80);
Add("1994", "ACT", 40);
Add("1994", "WA2", 200);
Add("1994", "SA2", 145);
Add("1994", "QLD2", 65);
Add("1994", "VIC2", 120);
Add("1994", "NSW2", 180);
Add("1994", "TAS2", 55);
Add("1994", "NT2", 80);
Add("1994", "ACT2", 40);
Add("1994", "WA3", 200);
Add("1994", "SA3", 145);
Add("1994", "QLD3", 65);
Add("1994", "VIC3", 120);
Add("1994", "NSW3", 180);
Add("1994", "TAS3", 55);
Add("1994", "NT3", 80);
Add("1994", "ACT3", 40);
Add("1994", "WA4", 200);
Add("1994", "SA4", 145);
Add("1994", "QLD4", 65);
Add("1994", "VIC4", 120);
Add("1994", "NS4", 180);
Add("1994", "TAS4", 55);
Add("1994", "NT4", 80);
Add("1994", "ACT4", 40);
Add("1994", "WA5", 200);
Add("1994", "SA5", 145);
Add("1994", "QLD5", 65);
Add("1994", "VIC5", 120);
Add("1994", "NS5", 180);
Add("1994", "TAS5", 55);
Add("1994", "NT5", 80);
Add("1994", "ACT5", 40);
}
*/